package com.Lgwd.repository;

import com.Lgwd.entity.BackInfoEntity;
import com.Lgwd.entity.UserItemInfoEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface BackInfoRepository extends JpaRepository<BackInfoEntity,Integer> {

    /**
     * 按照账号查询背包所有物品
     */
    @Query(value="select * FROM `backinfo` where user_account=?1 and flag=?2" , nativeQuery = true)
    List<BackInfoEntity> findByUser_accountAndFlag(@Param("user_account")String user_account,@Param("flag")Integer flag);

    /**
     * 查询该物品是否已穿戴
     * @param item_id
     * @param flag
     * @return
     */
    @Query(value="select * FROM `backinfo` where item_id=?1 and flag=?2" , nativeQuery = true)
    BackInfoEntity findByItem_idAAndFlag(@Param("item_id")String item_id,@Param("flag")Integer flag);

    /**
     * 根据装备类型查询是否穿戴了相同装备 进行替换
     * @param item_code_id
     * @param flag
     * @return
     */
    @Query(value="select * FROM `backinfo` where item_code_id=?1 and flag=?2 and user_account=?3" , nativeQuery = true)
    List<BackInfoEntity> findByItem_code_id(@Param("item_code_id")Integer item_code_id,@Param("flag")Integer flag,@Param("user_account")String user_account);
}
